/*
 * Copyright (c) 2022 Kirky-X
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "wm_gpio.h"
#include "wm_osal.h"

#define LED_INTERVAL_TICKER 300000
#define GPIO_PIN WM_IO_PB_08

enum LedState {
    LED_ON = 0,
    LED_OFF,
    LED_SPARK,
    LED_SLIGHT,
};

static void* LedStatus(enum LedState state)
{
    switch (state) {
    case LED_ON:
        printf("[LED STATE]>>>>>ON\n");
        tls_gpio_cfg(GPIO_PIN, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);
        break;
    case LED_OFF:
        printf("[LED STATE]>>>>>OFF\n");
        tls_gpio_cfg(GPIO_PIN, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_PULLHIGH);
        break;
    case LED_SPARK:
        printf("[LED STATE]>>>>>SPARK\n");
        tls_gpio_cfg(GPIO_PIN, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);
        tls_os_time_delay(LED_INTERVAL_TICKER);
        tls_gpio_cfg(GPIO_PIN, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_PULLHIGH);
        tls_os_time_delay(LED_INTERVAL_TICKER);
        tls_gpio_cfg(GPIO_PIN, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);
        tls_os_time_delay(LED_INTERVAL_TICKER);
        tls_gpio_cfg(GPIO_PIN, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_PULLHIGH);
        tls_os_time_delay(LED_INTERVAL_TICKER);
        break;
    case LED_SLIGHT:
        printf("[LED STATE]>>>>>SLIGHT\n");
        tls_gpio_cfg(GPIO_PIN, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_PULLLOW);
        break;
    default:
        break;
    }
}
